<template>
  <div class="loading_box">
    <div class="loading">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
    <div class="tip">
      <slot>拼命加载中...</slot>
    </div>
  </div>
</template>

<script setup lang="ts">

</script>

<style lang="less" scoped>
@import '../../assets/css/primary/index.less';

@loading-size: 14px;
@loading-spacing: 4px;
@loading-color: @primary-color;
@loading-animation-duration: 1s;

.loading_box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 40px;
}

.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  width: calc((@loading-size + @loading-spacing) * 3); // 动态计算宽度
  height: @loading-size * 2;
  font-size: 0;
  color: @loading-color;

  .item {
    width: @loading-size;
    height: @loading-size;
    margin: 0 @loading-spacing / 2;
    background-color: currentColor;
    border-radius: 50%;
    animation: ball-beat @loading-animation-duration infinite linear;

    &:nth-child(2n-1) {
      animation-delay: -0.5s;
    }
  }
}

// 动画效果
@keyframes ball-beat {
  50% {
    opacity: 0.2;
    transform: scale(0.75);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.tip {
  font-size: 12px;
  color: #333;
  margin-top: 8px;
}
</style>
